package demo1;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-01
 * Time: 22:41
 */

class Solution {
    public boolean canConstruct(String ransomNote, String magazine) {
        HashMap<Character,Integer> map1 = new HashMap<>();
        for(int i =0;i<ransomNote.length();++i){
            map1.put(ransomNote.charAt(i),map1.getOrDefault(ransomNote.charAt(i),0)+1);
        }
        HashMap<Character,Integer> map2 = new HashMap<>();
        for(int i =0;i<magazine.length();++i){
            map2.put(magazine.charAt(i),map2.getOrDefault(magazine.charAt(i),0)+1);
        }
        for(int i =0;i<ransomNote.length();++i){
            char ch = ransomNote.charAt(i);
            int x = map1.get(ch);
            int y = map2.get(ch);
            if(x>y){
                return false;
            }
        }
        return true;
    }
}
public class Test {

    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.canConstruct("a","b");
    }
}
